package cc.android.testapp.xp.hooker;

import android.app.Application;

import cc.android.testapp.cfg.CFG;
import cc.android.testapp.cfg.ConfigHelper;
import cc.android.testapp.util.CLog;
import cc.android.testapp.xp.HookBase;
import cc.android.testapp.xp.HookModule;
import cc.android.testapp.xp.hooker.adblock.util.XHook;
import cc.commons.util.reflect.MethodUtil;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

@HookModule(packages = "com.netease.cloudmusic", name = "网易云")
public class HookWYY extends HookBase implements ConfigHelper.IConfig {

    /**
     * 检索字符串shouldShowAd来找到正确的方法位置
     */
    @CFG
    private String mShowAdMethod = "com.netease.cloudmusic.music.base.bridge.ad.b.Q";

    @Override
    public String getCfgNode() {
        return "wyy";
    }

    @Override
    protected void hookToApp(XC_LoadPackage.LoadPackageParam pParam, Application pApp) throws Throwable {
        ClassLoader tLoader = pApp.getClassLoader();
        try {
            XHook.with(tLoader).match(new HBMethod(mShowAdMethod)).returnConstant(false);
        } catch (Throwable exp) {
            CLog.log("Hook " + this.getModuleName() + "启动页广告时发生错误", exp);
        }
    }
}
